<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<meta http-equiv="X-UA-COMPATIBLE" CONTENT="IE=edge">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>报关报检业务（在线支付）</title>
    <link href="<s:url value="../css/pay/index.css"/>" rel="stylesheet" type="text/css"/>
    <link href="<s:url value="../css/pay/submitOrder.css"/>" rel="stylesheet" type="text/css"/>
    <style type="text/css">
        .cost {
            height: 56px;
            line-height: 56px;
            text-align: left;
            padding-left: 58px;
            font-family: "宋体";
            font-size: 26px;
            font-weight: bold;
            background-color: #ebf2f7;
        }

        .num {
            text-decoration: underline;
        }

        .orderDetails {
            padding-top: 23px;
        }

        .whichBank {
            padding-left: 58px;
            padding-top: 47px;
            margin-left: 16px;
            margin-right: 16px;
            border-top: 2px solid #eeeeee;
        }

        .square {
            width: 14px;
            height: 14px;
            float: left;
            background-color: #000;
        }

        .choseBank {
            float: left;
            font-family: "宋体";
            font-size: 16px;
            margin-top: -2px;
            margin-left: 16px;
        }

        .bank {
            margin-top: 37px;
            padding-left: 30px;
        }

        .paiedBtn {
            clear: left;
            margin-top: 100px;
        }

        .spare {
            height: 630px;
        }

        .clear {
            clear: both;
        }

        .sex_box {
            text-align: left;
        }

        .sex_box a {
            float: left;
            padding-left: 35px;
            background: url(<s:url value="../img/radio.png"/>) 0px -34px no-repeat;
            display: inline-block;
            height: 28px;
            line-height: 20px;
            margin-right: 30px;
            cursor: pointer;
        }

        .sex_box a.checked {
            background: url(<s:url value="../img/radio.png"/>) no-repeat;
        }

        .a_paytype img {
            margin-top: -7px;
            margin-left: 10px;
        }
    </style>
    <script type="text/javascript"
            src="<s:url value="../js/jquery/jquery-1.8.0.min.js"/> "></script>
    <script type="text/javascript" src="<s:url value="../js/hint/jquery.hint.js"/>"></script>
    <script type="text/javascript"
            src="<s:url value="../js/jquery/jquery.json-2.2.js"/>"></script>
    <script type="text/javascript" src="<s:url value="../js/jw/jw.js"/>"></script>
    <script type="text/javascript" src="<s:url value="../js/pay/mousewheel.js"/>"></script>
    <script type="text/javascript" src="<s:url value="../js/pay/easyscroll.js"/>"></script>
    <script type="text/javascript" src="<s:url value="../js/pay/scrollInit.js"/>"></script>
    <script type="text/javascript" src="<s:url value="../js/ajaxutil.js"/>"></script>

    <script type="text/javascript">
        var sum_free = "${sum_free}";
        var balance = "${balance}";
        $(document).ready(function () {
//            if (sum_free == 0) {
//                window.close();
//            }
            $(".checkboxGroup label").click(function () {
                $(this).toggleClass("checked");
                $(this).parent().siblings(".checkboxGroup").children("label").removeClass(
                        "checked");
            });
            if (parseFloat(balance) < parseFloat(sum_free)) {
                $("#balance_paytype")[0].onclick = null;
                $("#balance_paytype").css("color", "grey");
                $("#balance_paytype .errmsg").text("余额不足")
            }
            /**
             * 显示后台错误
             */
            showErrorMessage();
        });
        function changePayAccountType(type, obj) {
            $(".a_paytype.checked").removeClass("checked");
            $(obj).addClass("checked");
            $("input[name='payAccountType']").val(type);
        }
        function gotoPay() {
            $("#payBtn").removeAttr('onclick');
            $("#payBtn").removeAttr('href');
            if ($("input[name='payAccountType']").val()) {
                $.ajax({
                           url: "<s:url value="/order/business-payMent?pay_id="/>" + $(
                                   "#pay_id").val() + "&paymentType="
                                + $("input[name='payAccountType']").val(),
                           dataType: "json",
                           type: "post",
                           data: {},
                           success: function (data) {
                               if (data.payMent != 'error') {
                                   if ("success" == data.payMent) {
                                       window.location.href =
                                               "<s:url value="/business/payAbcAction-payAbcSuccess?pay_id="/>${pay_id}";
                                   }
                                   else if ("balance_error" == data.payMent) {
                                       alert('余额不足');
                                       history.go(0)
                                   }
                                   else {
                                       alert('出现内部错误，即将结束本次支付！');
                                       window.location.href =
                                               "<s:url value="/business/unpaidMain"/>";
                                   }
                               } else {
                                   alert('订单存在不正确信息');
                               }

                           }
                       });
            } else {
                alert("请选择支付方式");
            }
        }

        function backToUnpaidMain() {
            parent.openUnpaidMainAndCurrentActiveTab();
        }

        /**
         * 提示错误信息
         */
        function showErrorMessage() {
            var errMessage = "${errorMessage}";
            if (errMessage) {
                alert("出错了！！ " + errMessage);
                location.href = "<s:url value="/business/unpaidMain" />";
            }
        }
    </script>
</head>
<body>
<div class="container">
    <div class="tab">
        <div class="completeStep">提交订单</div>
        <div class="completeStep">在线支付</div>
        <div>支付完成</div>

    </div>
    <div class="clear"></div>
    <div class="orderBox">
        <div class="spare">
            <div class="cost">
                <input type="hidden" id="pay_id" value="${pay_id}"/>
                订单总费用：￥<span class="num">${sum_free}</span>
            </div>
            <div class="orderDetails">
                <div class="thead">
                    <div>序号</div>
                    <div>订单号</div>
                    <div>价格</div>
                </div>

                <div class="tbodyDetails">
                    <div class="div_scroll">
                        <div class="div_scroll0">
                            <table>
                                <c:forEach var="declaration" items="${declarations}"
                                           varStatus='st'>
                                    <tr>
                                        <td>${st.index+1}</td>
                                        <td>${declaration.businessId}</td>
                                        <td><input type="text" id="free_${declaration.id}"
                                                   value="${declaration.declaration_free}"
                                                   disabled/>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </table>
                        </div>
                    </div>
                </div>
                <form>
                    <div class="whichBank">
                        <!--
                        <div class="square"></div>
                        <div class="choseBank">选择支付方式</div>
                        <div class="clear"></div>
                         -->
                        <div class="bank">
                            <div class="sex_box">
                                <input type="hidden" name="payAccountType" value="2">
                                <a class="checked a_paytype" id="balance_paytype"
                                   onclick="changePayAccountType('2',this)">余额支付(￥${balance})<span
                                        class="errmsg"></span>
                                    <span style="margin-left:40px;color:blue;"
                                          onclick="window.open('../fund/ajustment-main')">马上预付款</span>
                                    <span style="margin-left:40px;color:blue;"
                                          onclick="ajaxLoader.ajaxPost('../fund/ajustment-refreshFund',{},function(){window.history.go(0)})">刷新余额</span>
                                </a>
                            </div>
                        </div>

                    </div>
                    <div class="paiedBtn">
                        <a id="payBtn" href="#" class="submit" onclick="gotoPay()">在线支付</a><br>
                        <a id="backBtn" href="#" class="submit" style="background-color: #0c7ad7"
                           onclick="backToUnpaidMain()">返回</a><br>
                        <!-- <font style="color: red;">请您在支付成功后点击返回商户按钮!</font> -->
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>
